/*
 * @Description: 新增检测计划弹窗Reducer
 * @Author: Rfan
 * @Date: 2022-10-12 11:39:09
 * @LastEditTime: 2022-10-21 18:12:24
 */

import {
  SET_CURRENT_PLAN_INFO,
  SET_CURRENT_STEP,
  SET_DIALOG_TYPE,
  SET_DIALOG_VISIBLE,
  SET_LEVEL_FIELD_LIST,
  SET_LEVEL_LIST,
  SET_OBJ_TYPE,
  SET_RULE_OBJ
} from '../../../../constants';

export const AddPlanDialogReducer = (state, action) => {
  switch (action.type) {
    /**
     * @description: 设置弹窗展示状态
     */
    case SET_DIALOG_VISIBLE:
      return {
        ...state,
        visible: action.visible
      };

    /**
     * @description: 设置弹窗展示状态
     */
    case SET_DIALOG_TYPE:
      return {
        ...state,
        dialogType: action.data
      };

    /**
     * @description: 设置步骤条进度
     */
    case SET_CURRENT_STEP:
      return {
        ...state,
        currentStep: action.data
      };

    /**
     * @description: 表格加载loading
     */
    case SET_OBJ_TYPE:
      return {
        ...state,
        currentObjType: action.data
      };

    /**
     * @description: 设置被检测字段
     */
    case SET_LEVEL_FIELD_LIST:
      return {
        ...state,
        levelFieldList: action.data
      };

    /**
     * @description: 设置选中的档案类型
     */
    case SET_LEVEL_LIST:
      return {
        ...state,
        initRule: action.data || {}
      };

    /**
     * @description: 设置当前选中的方案数据
     */
    case SET_CURRENT_PLAN_INFO:
      return {
        ...state,
        currentPlanInfo: action.data
      };

    /**
     * @description: 编辑检测方案
     */
    case SET_RULE_OBJ: {
      return {
        ...state,
        currentRuleInfo: action.data
      };
    }

    default:
      console.log('untouched', action);
      return state;
  }
};
